package com.nmf.pc.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.nmf.dao.gen.BizGonggaoMapper;
import com.nmf.dao.gen.bean.BizGonggao;
import com.nmf.dao.gen.bean.BizGonggaoExample;
import com.nmf.pc.enums.GonggaoStatus;
import com.nmf.pc.vo.ReturnResult;

@Controller
@RequestMapping(value = "/pc")
public class PcGonggaoController {
	@Autowired
	BizGonggaoMapper bizGonggaoMapper;
	@RequestMapping(value = { "p/gonggao/infos" }, method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public ReturnResult periodInfos(HttpServletRequest request, HttpServletResponse response) throws IOException {
		ReturnResult returnResult = new ReturnResult();
		BizGonggaoExample bizGonggaoExample = new BizGonggaoExample();
		
		BizGonggaoExample.Criteria criteria = bizGonggaoExample.createCriteria();
		criteria.andStatusEqualTo(GonggaoStatus.online.value);

		List<BizGonggao>  blist = bizGonggaoMapper.selectByExample(bizGonggaoExample);
		for(BizGonggao bizGonggao : blist) {
			bizGonggao.setContent(null);
		}
		returnResult.setData(blist);
		return returnResult;
	}
	
	@RequestMapping(value = { "p/gonggao/detail" }, method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public ReturnResult detail(String id,HttpServletRequest request, HttpServletResponse response) throws IOException {
		ReturnResult returnResult = new ReturnResult();
		returnResult.setData(bizGonggaoMapper.selectByPrimaryKey(id));
		return returnResult;
	}
}
